﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace MainApp.Forms
{
    public partial class FormError : DevExpress.XtraEditors.XtraForm
    {
        public FormError()
        {
            InitializeComponent();
        }

        public void Show(Exception ex)
        {
            this.Text = "出现错误！";
            this.memoEdit1.EditValue = ex.Message + "\r" + ex.StackTrace;
            this.ShowDialog();
        }

        public void ShowMessage(IEnumerable<string> messages)
        {
            this.Text = "新的消息！";
            this.memoEdit1.EditValue = string.Join("\r\n", messages);
            this.ShowDialog();
        }

        public void ShowMessage(string messages)
        {
            this.Text = "新的消息！";
            this.memoEdit1.EditValue = messages;
            this.ShowDialog();
        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormError_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                this.Hide();
            }
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(this.memoEdit1.EditValue.ToString());
        }

        internal void ShowMessage(string title, params string[] messages)
        {
            if (messages.Count() == 0)
            {
                this.memoEdit1.EditValue = title;
            }
            else
            {
                this.Text = title;
                this.memoEdit1.EditValue = string.Join("\r\n", messages);
            }
            this.ShowDialog();
        }
    }
}